package cn.fl.project.controller;

import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.constant.SysOrgConstant;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.logger.eum.LogOperEnum;
import cn.cmm.base.framework.utils.*;
import cn.fl.framework.base.constant.WebBaseConstant;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.preloan.enums.LogBusinessTypeEnum;
import cn.fl.project.condition.PrjQuatPrpsCfgMQueryCondition;
import cn.fl.project.service.IPrjQuatPrpsCfgMService;
import cn.fl.project.vo.PrjQuatPrpsCfgDVO;
import cn.fl.project.vo.PrjQuatPrpsCfgMVO;
import cn.fl.system.constant.SysLogConstant;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lionbridge.log.ext.ExtSlf4jLogger;
import com.lionbridge.log.ext.ExtSlf4jLoggerBuilder;
import com.lionbridge.log.ext.LogTypeEnum;
import fl.constant.facade.framework.constant.BusinessIdConstant;
import fl.spl.facade.framework.constant.SplSystemConstant;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Description: 项目报价方案配置主信息表 控制层
 */
@Slf4j
@Controller
@RequestMapping("/project/prjQuatPrpsCfgM")
public class PrjQuatPrpsCfgMController extends BaseController {
	private static ExtSlf4jLogger logger = ExtSlf4jLoggerBuilder.create()
			.setLogger(log).setBusinessType(LogBusinessTypeEnum.QUOTATION_SCHEME.getCode())
			.setSubBusinessType(LogBusinessTypeEnum.QUOTATION_SCHEME.getCode())
			.setLogType(LogTypeEnum.BUSINESS).build().setKeywords("PrjQuatPrpsCfgM");
	/**
	 * PrjQuatPrpsCfgM 服务层BEAN
	 */
	@Autowired
	private IPrjQuatPrpsCfgMService prjQuatPrpsCfgMService;
	
	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("project/prjQuatPrpsCfgM/prjQuatPrpsCfgMList");
		return view;
	}

	/**
	 * 到新增/修改页面
	 */
	@RequestMapping(value = "/toAddPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toAddPage(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		ModelAndView view = new ModelAndView("project/prjQuatPrpsCfgM/prjQuatPrpsCfgMAdd");
		
		//获取下拉框数据
		//方案政策标准
		List<KeyValueVO> prpsTypCdList = this.prjQuatPrpsCfgMService.searchPrpsTypCdList();
		view.addObject("prpsTypCdList", prpsTypCdList);
		//方案产品类型
		List<KeyValueVO> prpsPrdTypCdList = this.prjQuatPrpsCfgMService.searchPrpsPrdTypCdList();
		view.addObject("prpsPrdTypCdList", prpsPrdTypCdList);
		//租赁期数单位
		List<KeyValueVO> lsPdUntCdList = this.prjQuatPrpsCfgMService.searchLsPdUntCdList();
		view.addObject("lsPdUntCdList", lsPdUntCdList);
		//支付方式
		List<KeyValueVO> payWayCdList = this.prjQuatPrpsCfgMService.searchPayWayCdList();
		view.addObject("payWayCdList", payWayCdList);
		//供应商返利政策
		List<KeyValueVO> splRebPolicyList = this.prjQuatPrpsCfgMService.searchSplRebPolicyList();
		view.addObject("splRebPolicyList", splRebPolicyList);
		//保证金处理方式
		List<KeyValueVO> dpstHdlWayCdList = this.prjQuatPrpsCfgMService.searchDpstHdlWayCdList();
		view.addObject("dpstHdlWayCdList", dpstHdlWayCdList);
		//租赁期满处理方式
		List<KeyValueVO> expHdlWayCdList = this.prjQuatPrpsCfgMService.searchExpHdlWayCdList();
		view.addObject("expHdlWayCdList", expHdlWayCdList);
		//是否
		List<KeyValueVO> yesOrNoCdList = this.prjQuatPrpsCfgMService.searchYesOrNoCdList();
		view.addObject("yesOrNoCdList", yesOrNoCdList);
		view.addObject("yesOrNoCdListJSON", JSON.toJSONString(yesOrNoCdList));
		//——————————————————————费用相关——————————————————————————————
		//费用类型
		JSONArray feeTypCdListJSON = this.prjQuatPrpsCfgMService.searchFeeTypCdList();
		view.addObject("feeTypCdListJSON", feeTypCdListJSON);
		//费用计算基数
		List<KeyValueVO> calBaseCdList = this.prjQuatPrpsCfgMService.searchCalBaseCdList();
		view.addObject("calBaseCdListJSON", JSON.toJSONString(calBaseCdList));
		//费用计入方式
		List<KeyValueVO> cntWayCdList = this.prjQuatPrpsCfgMService.searchCntWayCdList();
		view.addObject("cntWayCdListJSON", JSON.toJSONString(cntWayCdList));
		//事业部
		List<KeyValueVO> buOrgCdList = this.prjQuatPrpsCfgMService.searchBuOrgCdList();
		view.addObject("buOrgCdList", buOrgCdList);
		//获取当前登录人事业部
		String buOrgCd = CurrentThreadContext.getCurrentBuOrgCd();
		int length = SysOrgConstant.SYS_ORG_CD_LENGTH * SysOrgConstant.SYS_BU_ORG_CD_LVL;
		if(buOrgCd.length() == length){
			view.addObject("currentBuOrgCd", buOrgCd);
		}
		//费用比例小数位
		Map<String, String> demicMap = this.prjQuatPrpsCfgMService.getDecimalDigitsByBuOrgCode(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		view.addObject("demicMap", demicMap.isEmpty()==true?"":JSON.toJSONString(demicMap));
		
		view.addObject("id", id);
		logger.info("跳转到新增/修改页面.[id="+id+"]");
		return view;
	}
	
	/**
	 * 根据事业部代码获取比例小数位配置
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/getDemicMap.do",method = {RequestMethod.GET})
	@ResponseBody
	public Object getDemicMap(HttpServletRequest request,HttpServletResponse response){
		String buOrgCd = request.getParameter("buOrgCd");
		Map<String, String> demicMap = this.prjQuatPrpsCfgMService.getDecimalDigitsByBuOrgCode(CurrentThreadContext.getCurrentSysCd(), buOrgCd);
		return demicMap.isEmpty()==true?"":JSON.toJSONString(demicMap);
	}
	/**
	 * 到详情页面
	 */
	@RequestMapping(value = "/toDetailPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toDetailPage(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		ModelAndView view = new ModelAndView("project/prjQuatPrpsCfgM/prjQuatPrpsCfgMDetail");
		view.addObject("id", id);
		logger.info("跳转到详情页面.[id="+id+"]");
		return view;
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String prpsCfgNm = request.getParameter("prpsCfgNm");
		String expStDt = request.getParameter("expStDt");
		String expEndDt = request.getParameter("expEndDt");
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		PrjQuatPrpsCfgMQueryCondition qc = new PrjQuatPrpsCfgMQueryCondition();
		if (StringUtils.isNotEmpty(prpsCfgNm)) {
			qc.setPrpsCfgNm(prpsCfgNm);
		}
		if (StringUtils.isNotEmpty(expStDt)) {
			qc.setExpStDt(DateUtils.formatStringToDate(expStDt, DateUtils.YYYY_MM_DD));
		}
		if (StringUtils.isNotEmpty(expEndDt)) {
			qc.setExpEndDt(DateUtils.formatStringToDate(expEndDt, DateUtils.YYYY_MM_DD));
		}
		//设置查询条件所属事业部
		//qc.setBuOrgCd(CurrentThreadContext.getCurrentBuOrgCd());
		page.setCondition(qc);

		Pager pager = this.prjQuatPrpsCfgMService.searchListPage(page);
		List<PrjQuatPrpsCfgMVO> list = (List<PrjQuatPrpsCfgMVO>) pager.getResultList();
		ListPageVO<PrjQuatPrpsCfgMVO> listPage = new ListPageVO<PrjQuatPrpsCfgMVO>(list, pager.getTotalCount());
		logger.info("查询报价方案配置信息列表完成:list:{}", JSON.toJSONString(list));
		return listPage;
	}

	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeByIds.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String ids = request.getParameter("ids");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(ids)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			logger.info("删除报价方案配置信息失败，id为空");
			return result;
		}
		List<Long> idsList = new ArrayList<Long>();
		JSONArray idsArray = JSONArray.fromObject(ids);
		for (Object object : idsArray) {
			idsList.add(Long.valueOf(object.toString()));
		}
		try {
			boolean success = this.prjQuatPrpsCfgMService.removeByIds(idsList);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_DELETE_FAIL);
				logger.info("删除报价方案配置信息失败，接口错误removeById:{}",ids);
				return result;
			}
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error("删除报价方案配置信息失败，业务异常，msg:{}",ex.getMessage());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			logger.error("删除报价方案配置信息失败，系统异常,msg:{}",ex.getMessage());
		}

		return result;
	}

	/**
	 *  获取可用的方案列表
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@RequestMapping(value = "/getPrjQuatPrpsByConditon.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getPrjQuatPrpsByConditon(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String prjId = request.getParameter("prjId");
		Long id = null;
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		if(StringUtils.isNotBlank(prjId)){
			id = Long.valueOf(prjId);
		}

		PrjQuatPrpsCfgMQueryCondition qc = new PrjQuatPrpsCfgMQueryCondition();
		//设置查询条件所属事业部
		//qc.setBuOrgCd(CurrentThreadContext.getCurrentBuOrgCd());
		page.setCondition(qc);
		Pager pager = this.prjQuatPrpsCfgMService.searchIsUsePrjQuatPrpsCfgMList(page,id);
		ListPageVO<PrjQuatPrpsCfgMVO> listPage  = null;
		if(null==pager.getResultList()){
			listPage = new ListPageVO();
		}else{
			List<PrjQuatPrpsCfgMVO> list = (List<PrjQuatPrpsCfgMVO>) pager.getResultList();
			 listPage = new ListPageVO<PrjQuatPrpsCfgMVO>(list, pager.getTotalCount());
		}
		logger.info("获取可用的方案列表result:{}",JSONObject.toJSONString(page));
		return listPage;
	}

	
	
	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			logger.info("根据id获取报价方案配置信息详情,参数id为空");
			return result;
		}
		
		try {
			PrjQuatPrpsCfgMVO vo = this.prjQuatPrpsCfgMService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
				logger.info("根据id获取报价方案配置信息详情,数据不存在id：{}",id);
			}
			result.setData(vo);
			logger.info("根据id获取报价方案配置信息详情result:{}",JSONObject.toJSONString(vo));
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error("根据id获取报价方案配置信息详情,业务异常,msg:{}",ex.getMessage());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			logger.error("根据id获取报价方案配置信息详情,系统异常,msg:{}",ex.getMessage());
		}
		return result;
	}

	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		PrjQuatPrpsCfgMVO entity = null;
		try {
			entity = this.getRequestParamForPrjQuatPrpsCfgMAdd(request);
			Long id = this.prjQuatPrpsCfgMService.add(entity);
			logger.info("新增报价方案配置信息entity:{}", JSON.toJSONString(entity));
			result.setData(id);
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error("新增报价方案配置信息,业务异常,msg:{}",ex.getMessage());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			logger.error("新增报价方案配置信息,系统异常，msg:{}",ex.getMessage());
		}

		return result;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			logger.info("修改报价方案配置信息,id为空");
			return result;
		}
		PrjQuatPrpsCfgMVO entity = null;
		try {
			entity = this.getRequestParamForPrjQuatPrpsCfgMModify(request);
			entity.setId(Long.valueOf(id));
			boolean success = this.prjQuatPrpsCfgMService.modify(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
				logger.info("修改报价方案配置信息失败，业务异常entity:{}",JSONObject.toJSONString(entity));
			}
			logger.info("修改报价方案配置信息result:{}", JSON.toJSONString(entity));
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error("修改报价方案配置信息失败，业务异常，entity：{}，msg:{}",JSONObject.toJSONString(entity),ex.getMessage());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			logger.error("修改报价方案配置信息失败，系统异常entity:{},msg:{}",JSONObject.toJSONString(entity),ex.getMessage());
		}
		return result;
	}
	/**
	 * 启用报价方案
	 */
	@RequestMapping(value = "/enable.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object enable(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,SysLogConstant.LOG_CMM_ENABLE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			logger.info("启用报价方案失败，id为空");
			return result;
		}
		PrjQuatPrpsCfgMVO prjQuatPrpsCfgMVO = new PrjQuatPrpsCfgMVO();
		prjQuatPrpsCfgMVO.setId(Long.valueOf(id));
		//启用
		prjQuatPrpsCfgMVO.setIsValid(BaseConstant.IS_YESNO_YES);
		try {
			boolean success = this.prjQuatPrpsCfgMService.modifyEnAblePrjQuatPrpsCfgM(prjQuatPrpsCfgMVO);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_ENABLE_FAIL);
			}
			logger.info("启用报价方案result:{}", JSON.toJSONString(result));
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error("启用报价方案失败，业务异常,msg:{}",ex.getMessage());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			logger.error("启用报价方案失败，系统异常");
		}
		return result;
	}
	
	/**
	 * 禁用报价方案
	 */
	@RequestMapping(value = "/disable.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object disable(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,SysLogConstant.LOG_CMM_DISABLE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			logger.info("禁用报价方案失败，参数id为空");
			return result;
		}
		PrjQuatPrpsCfgMVO prjQuatPrpsCfgMVO = new PrjQuatPrpsCfgMVO();
		prjQuatPrpsCfgMVO.setId(Long.valueOf(id));
		//禁用
		prjQuatPrpsCfgMVO.setIsValid(BaseConstant.IS_YESNO_NO);
		try {
			boolean success = this.prjQuatPrpsCfgMService.modifyDisAblePrjQuatPrpsCfgM(prjQuatPrpsCfgMVO);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_DISABLE_FAIL);
			}
			logger.info("禁用报价方案id:{}",id);
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			logger.error("禁用报价方案失败，业务异常,msg:{}",ex.getMessage());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			logger.error("禁用报价方案失败，id为空");
		}
		return result;
	}
	
	//**************************************************私有方法************************************************/
	
	/**
	 * 获取请求参数
	 * @param request
	 * @return
	 * @throws BaseException
	 */
	private PrjQuatPrpsCfgMVO getRequestParamForPrjQuatPrpsCfgM(HttpServletRequest request) throws BaseException {
		String prpsCfgNm = request.getParameter("prpsCfgNm");//方案名称
		String prpsTypCd = request.getParameter("prpsTypCd");//方案政策标准
		String prpsCfgNo = request.getParameter("prpsCfgNo");//方案配置编号
		String prpsPrdTypCd = request.getParameter("prpsPrdTypCd");//方案产品类型
		String lsCoe = request.getParameter("lsCoe");//租赁系数
		String expStDt = request.getParameter("expStDt");//有效日期(起)
		String expEndDt = request.getParameter("expEndDt");//有效日期(止)
		String isAllowAdd = request.getParameter("isAllowAdd");//是否允许添加费用项
		String isSysDef = request.getParameter("isSysDef");//是否系统内置
		String payWayCd = request.getParameter("payWayCd");//支付方式
		String dpstHdlWayCd = request.getParameter("dpstHdlWayCd");//客户保证金处理方式
		String lsPd = request.getParameter("lsPd");//租赁期数
		String lsPdUntCd = request.getParameter("lsPdUntCd");//租赁期数单位
		String expHdlWayCd = request.getParameter("expHdlWayCd");//租赁期满处理方式
		String buOrgCd = request.getParameter("buOrgCd");//所属事业部
		String splRebPolicy = request.getParameter("splRebPolicy");//供应商返利政策
		//参数验证
		if (StringUtils.isEmpty(prpsCfgNm)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "方案名称不能为空!");
		}
		if (StringUtils.isEmpty(buOrgCd)) {
			buOrgCd = WebBaseConstant.SYS_P_ORG_CD;
		}
		if (StringUtils.isBlank(expStDt) || !DateUtils.isDate(expStDt, DateUtils.YYYY_MM_DD)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "有效日期(起)不能为空,并且为日期格式!");
		}
		
		if (StringUtils.isBlank(expEndDt) || !DateUtils.isDate(expEndDt, DateUtils.YYYY_MM_DD)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "有效日期(止)不能为空,并且为日期格式!");
		}
		
		if (DateUtils.formatStringToDate(expStDt, DateUtils.YYYY_MM_DD).after(DateUtils.formatStringToDate(expEndDt, DateUtils.YYYY_MM_DD))) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "有效日期(起)不能大于有效日期(止)!");
		}
		if(StringUtils.isEmpty(isAllowAdd)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "是否允许添加费用项必选项,不能为空.");
		}
		if(StringUtils.isEmpty(isSysDef)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "是否系统内置必选项,不能为空.");
		}
		//——————————————————————————————————————————————————————————————————————
		String lsPdUntCd_flag = request.getParameter("lsPdUntCd_flag");//1:租赁期数
		String payWayCd_flag = request.getParameter("payWayCd_flag");//2:支付方式
		String dpstHdlWayCd_flag = request.getParameter("dpstHdlWayCd_flag");//3:客户保证金处理方式
		String expHdlWayCd_flag = request.getParameter("expHdlWayCd_flag");//4:租赁期满处理方式
		String ai_flag = request.getParameter("ai_flag");//5:年利率
		if("true".equals(lsPdUntCd_flag)){
			lsPdUntCd_flag = String.valueOf(BaseConstant.IS_YESNO_NO);
		}else{
			lsPdUntCd_flag = String.valueOf(BaseConstant.IS_YESNO_YES);
		}
		if("true".equals(payWayCd_flag)){
			payWayCd_flag = String.valueOf(BaseConstant.IS_YESNO_NO);
		}else{
			payWayCd_flag = String.valueOf(BaseConstant.IS_YESNO_YES);
		}
		if("true".equals(dpstHdlWayCd_flag)){
			dpstHdlWayCd_flag = String.valueOf(BaseConstant.IS_YESNO_NO);
		}else{
			dpstHdlWayCd_flag = String.valueOf(BaseConstant.IS_YESNO_YES);
		}
		if("true".equals(expHdlWayCd_flag)){
			expHdlWayCd_flag = String.valueOf(BaseConstant.IS_YESNO_NO);
		}else{
			expHdlWayCd_flag = String.valueOf(BaseConstant.IS_YESNO_YES);
		}
		if("true".equals(ai_flag)){
			ai_flag = String.valueOf(BaseConstant.IS_YESNO_NO);
		}else{
			ai_flag = String.valueOf(BaseConstant.IS_YESNO_YES);
		}
		
		StringBuffer isAllowChg = new StringBuffer();//是否允许修改
		isAllowChg.append(lsPdUntCd_flag);
		isAllowChg.append(";");
		isAllowChg.append(payWayCd_flag);
		isAllowChg.append(";");
		isAllowChg.append(dpstHdlWayCd_flag);
		isAllowChg.append(";");
		isAllowChg.append(expHdlWayCd_flag);
		isAllowChg.append(";");
		isAllowChg.append(ai_flag);
		
		//详细信息(相关费用配置)参数
		String feeInfo = request.getParameter("feeInfo");
		logger.info("报价方案详细信息(相关费用配置)参数feeInfo:{}",JSONObject.toJSONString(feeInfo));
		//解析feeInfo
		List<PrjQuatPrpsCfgDVO> prjQuatPrpsCfgDVOList = new ArrayList<PrjQuatPrpsCfgDVO>();
		if (StringUtils.isNotBlank(feeInfo)) {
            prjQuatPrpsCfgDVOList = JSON.parseArray(feeInfo, PrjQuatPrpsCfgDVO.class);
		}
		logger.info("报价方案详配置详细信息prjQuatPrpsCfgDVOList:{}",JSONObject.toJSONString(prjQuatPrpsCfgDVOList));
		//处理费用金额
		if(CollectionUtils.isNotEmpty(prjQuatPrpsCfgDVOList)){
			for (PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO : prjQuatPrpsCfgDVOList) {
				//判断是否固定金额  是固定金额 金额 必填 不是固定金额 比例必填
				Integer isFixedAmt = prjQuatPrpsCfgDVO.getIsFixedAmt();
				Double fixedAmt = prjQuatPrpsCfgDVO.getFixedAmt();
				Double feePctMax = prjQuatPrpsCfgDVO.getFeePctMax();
				Double feePctMin = prjQuatPrpsCfgDVO.getFeePctMin();
				if(null==isFixedAmt){
					throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "请选择费用项是否为固定金额.");
				}
				if(BaseConstant.IS_YESNO_YES==isFixedAmt && null==fixedAmt){//是固定金额
					throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "费用项是固定金额,请填写具体金额数据.");
				}else if(BaseConstant.IS_YESNO_NO==isFixedAmt){
					if(null==feePctMax || null==feePctMin){
						throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "费用项不是固定金额,请填写具体比例值.");
					}
				}
				if(null!=prjQuatPrpsCfgDVO.getFixedAmt()){
					prjQuatPrpsCfgDVO.setFixedAmt(DecimalUtils.mul(prjQuatPrpsCfgDVO.getFixedAmt(), 100));
				}
			}
		}
		
		PrjQuatPrpsCfgMVO prjQuatPrpsCfgMVO = new PrjQuatPrpsCfgMVO();
		prjQuatPrpsCfgMVO.setPrpsCfgNm(prpsCfgNm.trim());
		if(StringUtils.isNotEmpty(prpsCfgNo)){
			prjQuatPrpsCfgMVO.setPrpsCfgNo(prpsCfgNo);
		}else{
			prjQuatPrpsCfgMVO.setPrpsCfgNo(prpsCfgNm+"-"+new Date().getTime());
		}
		prjQuatPrpsCfgMVO.setPrpsPrdTypCd(prpsPrdTypCd);
		prjQuatPrpsCfgMVO.setPrpsTypCd(prpsTypCd);
		if(StringUtils.isNotEmpty(lsCoe)){
			prjQuatPrpsCfgMVO.setLsCoe(Double.valueOf(lsCoe));
		}
		prjQuatPrpsCfgMVO.setExpStDt(DateUtils.formatStringToDate(expStDt, DateUtils.YYYY_MM_DD));
		prjQuatPrpsCfgMVO.setExpEndDt(DateUtils.formatStringToDate(expEndDt, DateUtils.YYYY_MM_DD));
		if(StringUtils.isNotEmpty(isAllowChg.toString())){
			prjQuatPrpsCfgMVO.setIsAllowChg(isAllowChg.toString());
		}
		if(StringUtils.isNotEmpty(isSysDef)){
			prjQuatPrpsCfgMVO.setIsSysDef(Integer.valueOf(isSysDef));
		}
		prjQuatPrpsCfgMVO.setPayWayCd(payWayCd);
		prjQuatPrpsCfgMVO.setDpstHdlWayCd(dpstHdlWayCd);
		if(StringUtils.isNotEmpty(lsPd)){
			prjQuatPrpsCfgMVO.setLsPd(Long.valueOf(lsPd));
		}
		prjQuatPrpsCfgMVO.setLsPdUntCd(lsPdUntCd);
		prjQuatPrpsCfgMVO.setExpHdlWayCd(expHdlWayCd);
		prjQuatPrpsCfgMVO.setPrjQuatPrpsCfgDVOList(prjQuatPrpsCfgDVOList);
		prjQuatPrpsCfgMVO.setBuOrgCd(buOrgCd);
		if(StringUtils.isNotEmpty(isAllowAdd)){
			prjQuatPrpsCfgMVO.setIsAllowAdd(Integer.valueOf(isAllowAdd));
		}
		prjQuatPrpsCfgMVO.setSplRebPolicy(splRebPolicy);
		//设置当前事业部代码为新增方案的事业部代码
		/*SysOrgDTO orgDTO = this.sysOrgApiService.selectSysOrgByOrgCd(CurrentThreadContext.getCurrentOrgCd(), CurrentThreadContext.getCurrentSysCd());
		if(orgDTO.getOrgTypCd().equals(SysOrgConstant.SYS_ORG_ORG_TYP_CD_IS_BUSI)){
			prjQuatPrpsCfgMVO.setBuOrgCd(orgDTO.getOrgCd());
		}*/
		return prjQuatPrpsCfgMVO;
	}
	
	/**
	 * 获取报价方案请求参数(新增)
	 * @param request 请求
	 * @return 
	 */
	private PrjQuatPrpsCfgMVO getRequestParamForPrjQuatPrpsCfgMAdd(HttpServletRequest request)throws BaseException{
		PrjQuatPrpsCfgMVO prjQuatPrpsCfgMVO = this.getRequestParamForPrjQuatPrpsCfgM(request);
		prjQuatPrpsCfgMVO.setCrtTm(new Date());
		prjQuatPrpsCfgMVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
		//设置明细的创建时间
		List<PrjQuatPrpsCfgDVO> prjQuatPrpsCfgDVOList = prjQuatPrpsCfgMVO.getPrjQuatPrpsCfgDVOList();
		if(CollectionUtils.isNotEmpty(prjQuatPrpsCfgDVOList)){
			for (PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO : prjQuatPrpsCfgDVOList) {
				prjQuatPrpsCfgDVO.setCrtTm(new Date());
				prjQuatPrpsCfgDVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			}
		}
		return prjQuatPrpsCfgMVO;
	}
	
	/**
	 * 获取报价方案请求参数(修改)
	 * @param request 请求
	 * @return 
	 */
	private PrjQuatPrpsCfgMVO getRequestParamForPrjQuatPrpsCfgMModify(HttpServletRequest request)throws BaseException{
		PrjQuatPrpsCfgMVO prjQuatPrpsCfgMVO = this.getRequestParamForPrjQuatPrpsCfgM(request);
		prjQuatPrpsCfgMVO.setMdfTm(new Date());
		prjQuatPrpsCfgMVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
		////设置明细的创建时间
		List<PrjQuatPrpsCfgDVO> prjQuatPrpsCfgDVOList = prjQuatPrpsCfgMVO.getPrjQuatPrpsCfgDVOList();
		if(CollectionUtils.isNotEmpty(prjQuatPrpsCfgDVOList)){
			for (PrjQuatPrpsCfgDVO prjQuatPrpsCfgDVO : prjQuatPrpsCfgDVOList) {
				prjQuatPrpsCfgDVO.setMdfTm(new Date());
				prjQuatPrpsCfgDVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
			}
		}
		return prjQuatPrpsCfgMVO;
	}
}

